class Solution {
public:
    ListNode* deleteDuplicates(ListNode* head) {
         if (!head) {
            return head;
        }

        ListNode* r = head;
        while (r->next) {
            if (r->val == r->next->val) {
                r->next = r->next->next;
            }
            else {
                r = r->next;
            }
        }

        return head;
    }
};